import 'package:flutter/material.dart';
import 'package:flutter_deer/account/models/user_score_deposit_entity.dart';
import 'package:flutter_deer/widgets/state_layout.dart';

class BelowUserDepositScorePageProvider extends ChangeNotifier {

  BelowUserScoreDepositPageEntity? _page;
  BelowUserScoreDepositStatisticsEntity? _statisticsEntity;
  List<BelowUserScoreDepositEntity>? _list = [];
  StateType? _stateType = StateType.loading;
  StateType? _statisticsStateType = StateType.loading;
  int? _currentPage = 1;

  BelowUserScoreDepositPageEntity? get belowUserScoreDepositPage => _page;
  BelowUserScoreDepositStatisticsEntity? get statisticsEntity => _statisticsEntity;
  double? get totalScore => _statisticsEntity!.totalScore;
  int? get totalTimes => _statisticsEntity!.totalTimes;
  int? get total => _page!.total;
  int? get current => _page!.current;
  List<BelowUserScoreDepositEntity>? get records => _page!.records;
  List<BelowUserScoreDepositEntity>? get list => _list;
  bool? get hasMore => _page!.current!<_page!.pages!;
  StateType? get stateType => _stateType;
  StateType? get statisticsStateType => _statisticsStateType;
  int? get currentPage => _currentPage;

  void setStatistics(BelowUserScoreDepositStatisticsEntity? entity){
    this._statisticsEntity = entity;
    this._statisticsStateType = StateType.takeOut;
    notifyListeners();
  }

  void setBelowUserDepositScorePage(BelowUserScoreDepositPageEntity? pageEntity){
    this._page = pageEntity;
    this._currentPage = pageEntity!.current;
    if(pageEntity.current==1) {
      this._list = pageEntity!.records;
    }else{
      for(int i=0;i<pageEntity.records!.length;i++){
        BelowUserScoreDepositEntity item = pageEntity.records!.elementAt(i);
        this._list!.add(item);
      }
    }
    this._stateType = StateType.takeOut;
    notifyListeners();
  }

}